package com.outputstream_;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Vhong
 * @version 1.0
 */
public class FileCopy {
    public static void main(String[] args)  {
        //1.创建的文件的输入流
        //2.创建文件的输出流，将读取到的文件数据，写入到指定的文件
        String srcFilePath = "g:\\绘梨衣.webp";
        String  destFilePath = "e:\\梨衣2.webp";
       //定义一个字节数组，提高读取效果
        byte[] buf = new byte[1024];
        int readLen = 0;

        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;

        try {
            fileInputStream  = new FileInputStream(srcFilePath);
            fileOutputStream = new FileOutputStream(destFilePath);
            while ((readLen = fileInputStream.read(buf)) != -1){
                //读取到后，就写入到文件 通过 fileOutputStream
                //即，是一边读，一边写
                //一定要使用这个方法
                fileOutputStream.write(buf,0,readLen);

            }
            System.out.println("拷贝成功~");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(fileInputStream != null)
                fileInputStream.close();
                if(fileOutputStream != null)
                    fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
